********************************************************************************
*
* What do parents want? Parental spousal prefernces in China
* Date: September 2021
*
* MAIN STUDENT Preference estimation (for section 6.1)
* 
* Stata version 15
* This do file: Generate table 10 and 11, figure 12
*
* other do file: 
* MAIN QSAMPY Preferences estimation (for section 4)
* 
* other R scripts:
* MAIN Simulation (for section 5.2. and appendix)
* acceptance sets (for section 6.2)
* marriage distribution graphs
********************************************************************************

** working directory: folder where data is saved and where output will be saved
cd ""

set scheme s1mono
set more off
set matsize 800

***************************** summary statistics *******************************
********************** table 3 *************************************************
**** no output: copy and pasted
use "summary_statistics_uni.dta", clear
sum search_female age subject*
sutex search_female age subject*, label


************************** PREFERENCE ESTIMATION  *******************************

use "meet_data_final.dta", clear

**** STUDENT SAMPLE
keep if uni==1
gen female =(gender==1)

********************************************************************************
********************** table 10  *************************************

logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_neg profilereal i.id_num ///
 if female==1, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_neg profilereal)
			est store A
logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_pos2 age_diff_neg age_diff_neg2  profilereal i.id_num ///
 if female==1, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_pos2 age_diff_neg age_diff_neg2 profilereal)
			est store B		
logit meet edu_diff_pos edu_diff_neg han c.profloginc c.age_diff_pos  age_diff_neg profilereal i.id_num ///
 if female==1, cluster(id_num)
 estpost margins, dydx(edu_diff_pos edu_diff_neg han profloginc age_diff_pos age_diff_neg profilereal)
			est store C	
			
logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_neg profilereal i.id_num ///
 if female==0, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_neg profilereal)
			est store D
logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_pos2 age_diff_neg age_diff_neg2  profilereal i.id_num ///
 if female==0, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_pos2 age_diff_neg age_diff_neg2 profilereal)
			est store E		
logit meet edu_diff_pos edu_diff_neg han c.profloginc c.age_diff_pos age_diff_neg profilereal i.id_num ///
 if female==0, cluster(id_num)
 estpost margins, dydx(edu_diff_pos edu_diff_neg han profloginc age_diff_pos age_diff_neg profilereal)
			est store F	
			
		
set matsize 800	
esttab A B C D E F using tab1_students.tex, replace label nobaselevels interaction(" X ") se f compress nogaps  noomit  ///
star( * 0.10 ** 0.05 *** 0.01) 


********************** table 11 *************************************
gen minority = (Cethnicity !=1)
gen minority_interaction = minority*han
label var minority_interaction "Subject:  Minority X Profile:  Han ethnicity" 
gen rural_childhood = (Cchildhood_rural ==1 | Cchildhood_rural== 3)
gen rural_childhood_interaction = rural_childhood*han
label var rural_childhood_interaction "Subject:  Rural childhood X Profile:  Han ethnicity" 


logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_neg profilereal rural_childhood_interaction i.id_num ///
 if female==1, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_neg profilereal rural_childhood_interaction )
			est store A
			logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_neg profilereal minority_interaction i.id_num ///
 if female==1, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_neg profilereal minority_interaction )
			est store B
			
logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_neg profilereal i.id_num  rural_childhood_interaction  ///
 if female==0, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_neg profilereal rural_childhood_interaction)
			est store C
logit meet i.profileedu han c.profloginc c.age_diff_pos age_diff_neg profilereal i.id_num  minority_interaction  ///
 if female==0, cluster(id_num)
 estpost margins, dydx(profileedu han profloginc age_diff_pos age_diff_neg profilereal minority_interaction)
			est store D
			
			
set matsize 800	
esttab A B C D using tab1_students_interact.tex, replace label nobaselevels interaction(" X ") se f compress nogaps  noomit  ///
star( * 0.10 ** 0.05 *** 0.01) 




*** Figure 12
replace age_diff_neg = - age_diff_neg
logit meet c.edu_diff_pos c.edu_diff_neg han c.profloginc c.age_diff_pos##c.age_diff_pos c.age_diff_neg##c.age_diff_neg profilereal i.id_num ///
 if female==0, cluster(id_num)
			margins, at( age_diff_neg=(0(1)-10)  age_diff_pos=(0))
			marginsplot, ylabel(0(0.2)1)
graph export age_student_neg_male.png, replace
			margins, at( age_diff_pos=(0(1)10)  age_diff_neg=(0))
			marginsplot, ylabel(0(0.2)1) 
graph export age_student_pos_male.png, replace			

logit meet c.edu_diff_pos c.edu_diff_neg han c.profloginc c.age_diff_pos##c.age_diff_pos c.age_diff_neg##c.age_diff_neg profilereal i.id_num ///
 if female==1, cluster(id_num)
			margins, at( age_diff_neg=(0(1)-10)  age_diff_pos=(0))
			marginsplot
graph export age_student_neg_female.png, replace
			margins, at( age_diff_pos=(0(1)10)  age_diff_neg=(0))
			marginsplot
graph export age_student_pos_female.png, replace

replace age_diff_neg = - age_diff_neg

